
import numpy as np

from implement.models.mlp import MLP
from implement.optimizers.momentum_sgd import MomentumSGD
from utils.functions_collect import mean_squared_error

np.random.seed(8)
x = np.random.rand(100, 1)
y = np.sin(2 * np.pi * x) + np.random.rand(100, 1)

lr = 0.2
max_iter = 10000
hidden_size = 10
model = MLP((hidden_size, 1))
optimizer = MomentumSGD(lr)
optimizer.setup(model)

for i in range(max_iter):
    y_pred = model(x)
    loss = mean_squared_error(y,y_pred)
    model.cleargrads()
    loss.backward()
    optimizer.update()
    if i % 1000 == 0:
        print(loss.data)

